import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/lifeCircle/data/api/life_topic_list_api.dart';
import 'package:casdon/modules/lifeCircle/data/repository/life_repository.dart';
import 'package:casdon/modules/lifeCircle/providers/life_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class LifeSelfTopicListUsecase {
  final LifeRepository _repository;

  const LifeSelfTopicListUsecase(this._repository);

  Future<ResponseLifeTopicListApi> execute({
    required int pageNum,
    required int pageSize,
  }) async {
    try {
      var ret = await _repository.getSelfSubjectList(
        pageNum: pageNum,
        pageSize: pageSize,
      );
      ret ??= ResponseLifeTopicListApi(0, []);
      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("LifeSelfTopicListUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("LifeSelfTopicListUsecase 失败");
    }
  }
}

final lifeSelfTopicListUsecaseProvider = Provider(
  (ref) => LifeSelfTopicListUsecase(ref.read(lifeRepository)),
);
